import json
from django.views.generic.base import View
from django.http import HttpResponse,JsonResponse
from django.forms.models import model_to_dict
from django.core import serializers

from goods.models import Goods

class GoodsListView(View):
     def get(self,request):
        json_list=[]
        goods=Goods.objects.all()[:10]
        # for good in goods:
        #     json_dict={}
            #  json_dict['name']=good.name
            #  json_dict['market_price']=good.market_price
            #  json_list.append(json_dict)
            # json_dict=model_to_dict(good)
            # json_list.append(json_dict)
        json_data=serializers.serialize('json',goods)
        json_data=json.loads(json_data)
        return JsonResponse(json_data,safe=False)
        # return HttpResponse(json.dumps(json_list ,ensure_ascii=False),content_type='application/json')
        # return HttpResponse(json_data,content_type='application/json')

